package org.phalanx.gwt.client.shared;

import java.util.Date;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;

public class WebClientFeedManager implements RequestCallback {
	// Class manages initiating the client feed
	private MessageManager msgMgr;
	
	public WebClientFeedManager(MessageManager msgMgr){
		this.msgMgr = msgMgr;
	}
	
	public boolean initiateFeed(){
		boolean isSuccess = false;
		try {
			String millisecondsReq = new Date().getTime() + "";
			RequestBuilder postMessenger = new RequestBuilder(RequestBuilder.GET, 
					"/PhalanxServlet/ServerInstance?context=listenfeed&time=" + millisecondsReq);
			postMessenger.sendRequest(null, msgMgr);
			isSuccess = true;
		} catch (RequestException e) {}
		return isSuccess;
	}

	@Override
	public void onError(Request request, Throwable exception) {
		
	}

	@Override
	public void onResponseReceived(Request request, Response response) {
		String s = response.getText();
	}
}
